rm(list=ls())
setwd("insert file path here")
library(foreign)
install.packages("readstata13")
library("readstata13")
library("sm")



###### Study 1


data1<-read.dta13("Replication_Study1_DataFile.dta")

## Figure A. II. 1 

aggregate(data1$dv_keep7, list(data1$t_interests), mean)

png("Figure_A_II_1.png", width=8, height=6, units='in', res=300)
sm.density.compare(data1$dv_keep7, data1$t_interests, xlab="Support for Alliance Maintenance ", col=c("blue", "red"), xlim=c(1,7))
abline(v=c(4.972), col=c("blue"))
abline(v=c(5.238), col=c("red"), lty=2)
legend(1, 0.37, legend=c("Interest=0", "Interest=1"),
       col=c("blue", "red"), lty=1:2, cex=0.8,
       box.lty=0)
dev.off()


aggregate(data1$dv_keep7, list(data1$t_values), mean)

png("Figure_A_II_2.png", width=8, height=6, units='in', res=300)
sm.density.compare(data1$dv_keep7, data1$t_values, xlab="Support for Alliance Maintenance", col=c("orange", "green"))
abline(v=c(4.952), col=c("orange"))
abline(v=c(5.258), col=c("green"), lty=2)
legend(-0.5, 0.37, legend=c("Value=0", "Value=1"),
       col=c("orange", "green"), lty=1:2, cex=0.8,
       box.lty=0)
dev.off()





###### Study 2 


data2<-read.dta13("Replication_Study2_DataFile.dta")

data2$treat<-as.factor(data2$treat)

###Figure A.II.3.


aggregate(data2$dv_keep7, list(data2$treat), mean)


png("FigureA_II_3.png", width=8, height=6, units='in', res=300)

sm.density.compare(data2$dv_keep7, data2$treat, xlab="Support for Alliance Maintenance", col=c("blue", "red", "orange","green","black"))

abline(v=c(5.321), col=c("blue"))
abline(v=c(4.903), col=c("red"))
abline(v=c(5.477), col=c("orange"))
abline(v=c(5.564), col=c("green"))
abline(v=c(5.715), col=c("black"))
legend(-0.5, 0.35, legend=c("Control", "No Values,No Interests", "Values, No Interests", "No Values, Interests", "Values,Interests"),
       col=c("blue","red","orange", "green", "black"), lty=1:2, cex=0.8,
       box.lty=0)

dev.off()


###Figure A.II.4. 



aggregate(data2$dv_crisis7, list(data2$treat), mean)


png("FigureA_II_4.png", width=8, height=6, units='in', res=300)

sm.density.compare(data2$dv_crisis7, data2$treat, xlab="Alliance Support During Crisis", col=c("blue", "red", "orange","green","black"))

abline(v=c(4.639), col=c("blue"))
abline(v=c(4.504), col=c("red"))
abline(v=c(4.880), col=c("orange"))
abline(v=c(4.930), col=c("green"))
abline(v=c(5.109), col=c("black"))
legend(-0.5, 0.30, legend=c("Control", "No Values, No Interests", "Values, No Interests", "No Values, Interests", "Values, Interests"),
       col=c("blue","red","orange", "green", "black"), lty=1:2, cex=0.8,
       box.lty=0)
dev.off()